/*
Write a function to find the longest common prefix string amongst an array of strings.
*/

class Solution {
public:
    string longestCommonPrefix(vector<string> &strs) {
        string prefix; int index = 0;
        if (!strs.size()) return prefix;
        while (index < strs[0].length()) {
            bool match = true;
            for (int i = 1; i < strs.size(); i++) {
                if (index >= strs[i].length() || 
                    strs[i].at(index) != strs[0].at(index)) {match = false; break;}
            }
            if (match) prefix += strs[0].at(index);
            else break;
            index ++;
        }
        return prefix;
    }
};
